/*****
 * Tencent is pleased to support the open source community by making QMUI_iOS available.
 * Copyright (C) 2016-2019 THL A29 Limited, a Tencent company. All rights reserved.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://opensource.org/licenses/MIT
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 *****/

#import <Foundation/Foundation.h>

@interface NSArray<ObjectType> (YsToolsManager)

/// 将多个对象合并成一个数组，如果参数类型是数组则会将数组内的元素拆解出来加到 return 内（只会拆解一层，所以多维数组不处理）
/// @param object object 要合并的多个数组
+ (instancetype)qmui_arrayWithObjects:(id)object, ...;

/// 将多维数组打平成一维数组再遍历所有子元素
/// @param block block
- (void)qmui_enumerateNestedArrayWithBlock:(void (^)(id obj, BOOL *stop))block;

/// 将多维数组递归转换成 mutable 多维数组
- (NSMutableArray *)qmui_mutableCopyNestedArray;

/// 过滤数组元素，将 block 返回 YES 的 item 重新组装成一个数组返回
/// @param block block
- (NSArray<ObjectType> *)qmui_filterWithBlock:(BOOL (^)(ObjectType item))block;

/// 转换数组元素，将每个 item 都经过 block 转换成一遍 返回转换后的新数组
/// @param block block
- (NSArray *)qmui_mapWithBlock:(id (^)(ObjectType item))block;

/// 深拷贝
- (NSMutableArray *)mutableArrayDeeoCopy;

/// 比较数组元素一直 无序
/// @param otherArray 比较素组
- (BOOL)qmui_isEqualToArray:(NSArray *)otherArray;

/// 数组是否为空
- (BOOL)isEmpty;

/// 数组元素拼接
-(NSString *(^)(NSString *separator))joinedByString;


/// 返回第一个元素的角标
/// 返回-1代表失败
- (NSInteger)qmui_firstIndexWithBlock:(BOOL (^)(ObjectType item))block;

/// 返回第一个元素的对象
/// 返回nil代表失败
- (ObjectType)qmui_firstObjectWithBlock:(BOOL (^)(ObjectType item))block;

/// 去掉重复元素，将 block 返回 YES 的 item 重新组装成一个数组返回
/// @param block block
/// 能用NSSet去重就用NSSet，这个方法复杂度太高了 O(n^2)
/// 默认去重后面的相同的元素
///    NSArray *array = @[
///    [[HLEPerson alloc] initWithName:@"rose1" idCard:@"11"],
///    [[HLEPerson alloc] initWithName:@"rose2" idCard:@"22"],
///    [[HLEPerson alloc] initWithName:@"rose3" idCard:@"33"],
///    [[HLEPerson alloc] initWithName:@"rose4" idCard:@"33"],
///                 ];
///      NSArray *removeDuplicateArray = [array                   qmui_removeDuplicateWithBlock:^BOOL(HLEPerson *item1, HLEPerson * item2) {
///             return [item1.idCard isEqualToString:item2.idCard];
///       }];
///
- (NSArray<ObjectType> *)qmui_removeDuplicateWithBlock:(BOOL (^)(ObjectType item1,ObjectType item2))block;

@end
